package com.apes.fn.scm.settleCheck.reponsitory;

import com.apes.fn.scm.settleCheck.model.PartnerCheck;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/**
 * 功能：
 *
 * @author zhuyh
 * @time 16:08
 * @date 2020/2/28
 */
public interface PartnerCheckRepository extends CustomRepository<PartnerCheck, String> {


    @Query("select T from PartnerCheck T  where T.fnCustomer.id=?1 and T.startDate<=?2 and T.endDate>=?3 and T.state=?4 ")
    List<PartnerCheck> findAllByFnCustomerAndState(String merchantId, Date startDate, Date endDate, String state);

    @Query(value = "SELECT A.* FROM FN_PARTNER_CHECK A LEFT JOIN MAS_STORE B ON A.FN_CUSTOMER_ID = B.COMPANY_ID " +
            "WHERE A.START_DATE <= :date AND A.END_DATE >= :date AND  A.STATE = :state AND (B.CLOSING_DAY IS NULL OR B.CLOSING_DAY >= :date)",nativeQuery = true)
    List<PartnerCheck> findAllByState(@Param("date") Date date, @Param("state") String state);


}
